<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/js/jquery-1.10.1.min.js"></script>
<!--<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>-->
<script src="<?php echo URL::base() ?>media/laydate/laydate.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<style>
    .overflow-y td, .overflow-y th {
        font-size: 12px;
        min-width: 150px;
        text-align: center;
        }

    .mypage {
        display: none;
        }

    #txtHint {
        position: absolute;
        top: 30px;
        left: 104px;
        display: none;
        background-color: #EDFAF4;
        min-width: 281px;
        border: 1px solid;
        border-radius: 5px;
        height: 150px;
        overflow: auto;
        border: 1px solid #aaa;
        padding: 5px 2px;
        }

    #txtHint li {
        list-style: none;
        color: #333;
        border: 1px solid #EDFAF4;
        padding: 0px 8px;
        }

    #txtHint li:hover {
        color: #c37100;
        background-color: #fdf8d5;
        border: 1px solid #fac900;
        border-radius: 25px;
        }

    #detail span:hover {
        color: #c37100;
        }

    #group {
        position: relative;
        }



    .table tr th {
        font-weight: normal;
        }
    .table_t10{ margin-top: 20px;}
    .enletter {
        /*width: 200px;*/
        word-wrap: break-word;
        word-break: break-all;
        }
</style>


<form class="form-search form-horizontal" method="get"
      action="<?php echo URL::site('handlequality/handlequality_select'); ?>">
    <div class="control-group">
        <label class="control-label">是否库内:</label>
        <div class="controls">
            <select name="no_purchaseorder_id">
                <option value="0" <?php if ($no_purchaseorder_id == 0) {
                    echo "selected = 'selected'";
                } ?>>请选择
                </option>
                <option value="20" <?php if ($no_purchaseorder_id == 20) {
                    echo "selected = 'selected'";
                } ?>>非库内
                </option>
                <option value="10" <?php if ($no_purchaseorder_id == 10) {
                    echo "selected = 'selected'";
                } ?>>库内
                </option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">计划员:</label>
        <div class="controls">
            <input  name="purchase_man_name" type="text"
                   value="<?php if (isset($purchase_man_name)) {
                       echo $purchase_man_name;
                   } ?>"/>

        </div>
    </div>
    <div class="control-group">
            <label class="control-label">供应商:</label>
        <div class="controls">
            <input id="supplier_id" name="supplier" type="text"
                   value="<?php if (isset($supplier)) {
                       echo $supplier;
                   } ?>"/>
        </div>
        <div id="txtHint"   style="z-index:222px; margin-top:199px;margin-left:52px;overflow-x:hidden;"  ></div>
    </div>
        <div class="control-group">
            <label class="control-label">SKU:</label>
            <div class="controls">
            <input   name="sku" type="text"
                   value="<?php if (isset($sku)) {
                       echo $sku;
                   } ?>"/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">VMI单号: </label>
            <div class="controls">
            <input  onkeyup="this.value=this.value.replace(/\D/g,'')"
                   onafterpaste="this.value=this.value.replace(/\D/g,'')" name="purchaseorder_id" type="text"
                   value="<?php if (isset($purchaseorder_id)) {
                       echo $purchaseorder_id;
                   } ?>"/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">处理日期从:</label>
            <div class="controls">
            <input type="text"  name="date_from_c" id="date_from"
                   value="<?php if (isset($date_from_c)) {
                       echo $date_from_c;
                   } ?>"/>
            到
            <input  name="date_to_c" type="text"
                   id="date_to" value="<?php if (isset($date_to_c)) {
                echo $date_to_c;
            } ?>"/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">状态:</label>
            <div class="controls">
            <select name="fail_deal_way" id="fail_deal_way">
                <option value="1000" <?php if (isset($fail_deal_way)&& $fail_deal_way ==1000) {
                    echo 'selected="selected"';
                } ?>>所有
                </option>
                <?php
                foreach ($way as $ks => $v) {
                    ?>
                    <option value="<?php echo $v['number']; ?>" <?php if (isset($fail_deal_way) && $fail_deal_way == $v['number']) {
                        echo 'selected="selected"';
                    } ?>><?php echo $v['value']; ?></option>
                <?php } ?>

            </select>

            <select id="status_choose" name="status">
                <option value="1">不合格产品处理</option>
                <option value="20" <?php if (isset($status) and $status == 20) {
                    echo 'selected="selected"';
                } ?> >已出库
                </option>

                <option value="10" <?php if (isset($status) and $status == 10) {
                    echo 'selected="selected"';
                } ?> >待出库
                </option>
            </select>
            </div>
        </div>
            <div class="control-group">
                <div class="controls">
            <button type="submit" class="btn btn-info">查询</button>
            <a id="down" class="btn" style="display: ture">下载</a>&nbsp;&nbsp;&nbsp;<span
                    style="color: #ff0000">(量大时添加筛选条件后下载)</span></div>
            </div>

</form>


<?php
if (isset($orm)) {

    foreach ($orm as $k => $val) {

        ?>
        <form style="margin-bottom:20px; margin-top:20px;"
              action="<?php echo URL::site('handlequality/handlequality_check'); ?>" method="post" name="frm">
            <table class="table table-hover table_t10">
                <thead>
                <tr>
                    <th width="8%">不良品出库表单号</th>
                    <th width="8%">不良品处理单号</th>
                    <th width="8%">VMI预约单号</th>
                    <th width="8%">SKU</th>
                    <th width="15%">中文名称</th>
                    <th width="15%">供应商</th>
                    <th width="12%">不合格数量</th>
                    <th width="15%">质检不合格原因</th>
                    <th width="10%">质检人</th>
                </tr>
                </thead>
                <tr>
                    <!-- 不良品出库表单 -->
                    <td>
                        <?php echo $val['id']; ?>
                        <input type="hidden" name="id" id="id_<?php echo $val['id']; ?>"
                               value="<?php echo $val['id']; ?>"/>
                    </td>
                    <!-- 不良品处理单 -->
                    <td>
                        <?php echo $val['unqualified_id']; ?>
                        <input type="hidden" name="unqualified_id" id="unqualified_id_<?php echo $val['id']; ?>"
                               value="<?php echo $val['unqualified_id']; ?>"/>

                    </td>
                    <!-- VMI预约单号 -->
                    <td>
                        <?php echo $val['purchaseorder_id']; ?>
                        <input type="hidden" name="purchaseorder_id" id="purchaseorder_<?php echo $val['id']; ?>"
                               value="<?php echo $val['purchaseorder_id']; ?>"/>

                    </td>
                    <!-- SKU -->
                    <td>
                        <?php echo $val['sku']; ?>
                        <input type="hidden" name="sku" id="sku_<?php echo $val['id']; ?>"
                               value="<?php echo $val['sku']; ?>"/>
                    </td>
                    <!-- SKU名称 -->
                    <td>
                        <?php echo $val['sku_name']; ?>
                        <input type="hidden" name="sku_name" id="sku_name_<?php echo $val['id']; ?>"
                               value="<?php echo $val['sku_name']; ?>"/>
                    </td>
                    <!-- 供应商 -->
                    <td>
                        <?php echo $val['vProviderName'];//供应商
                        ?>
                        <input type="hidden" name="vProviderName" id="vProviderName_<?php echo $val['id']; ?>"
                               value="<?php echo $val['vProviderName']; ?>"/>

                    </td>
                    <!-- 不合格数量 -->
                    <td>
                        <input type="hidden" name="quantity" id="quantity_<?php echo $val['id']; ?>"
                               value="<?php echo $val['quantity']; ?>"/>
                        <?php echo $val['quantity']; ?>
                    </td>
                    <td class="enletter">
                        <?php echo $val['cc_remark'];
                        //if(isset($val['unqualified_reason'])){ echo $val['unqualified_reason'];}
                        ?>
                    </td>
                    <td>
                        <?php echo $quality_men[$val['id']] ?>
                    </td>

                </tr>
                <tr style="background-color:#f5f5f5;">
                    <th>计划员</th>
                    <th>处理人</th>
                    <th>实物出库备注</th>
                    <th>采购处理方式</th>
                    <th>采购处理备注</th>
                    <th>质检时间</th>
                    <th>处理时间</th>
                    <th>状态</th>
                    <th>操作</th>
                <tr>
                    <!-- 计划员 -->
                    <td>
                        <?php
                        echo $val['purchaser'];
                        //echo Erpuser::nick_by_id($val['operate_man']);
                        ?>
                    </td>
                    <!-- 处理人 -->
                    <td>
                        <?php
                        echo $val['operater'];
                        //echo Erpuser::nick_by_id($val['operate_man']);
                        ?>
                    </td>
                    <!-- 	实物出库备注 -->
                    <td>
                        <?php
                        if ($val['status'] == 20) {
                            echo $val['warehouse_remark'];
                        } else {

                            ?>
                            <input style="width:80px;" type="text" name="warehouse_remark"
                                   id="warehouse_remark_<?php echo $val['id']; ?>"
                                   value="<?php echo $val['warehouse_remark']; ?>"/>
                        <?php } ?>
                    </td>
                    <!-- 采购处理方式  -->
                    <td>
                        <?php
                        foreach ($way as $ks => $v) {
                            if ($v['number'] == $val['fail_deal_way']) {
                                ?>
                                <input type="hidden" name="fail_deal_way" id="fail_deal_way_<?php echo $val['id']; ?>"
                                       value="<?php echo $v['number']; ?>"/>
                                <?php
                                echo $v['value'];
                                break;
                            }
                        }
                        ?>
                    </td>
                    <!-- 采购处理备注 -->
                    <td>
                        <?php echo $val['unqualified_reason']; ?>
                    </td>
                    <!-- 质检时间 -->
                    <td>
                        <?php echo $val['zhijian_time']; ?>
                    </td>
                    <!-- 处理时间 -->
                    <td>
                        <?php echo $val['deal_time']; ?>
                    </td>
                    <!-- 状态 -->
                    <td>
                        <?php if ($val['status'] == 10) {
                            echo '待出库';
                        } else {
                            echo '已出库';
                        } ?>

                    </td>
                    <!-- 操作-->
                    <td>
                        <?php
                        if ($val['status'] == 10) {
                            ?>
                            <input type="button" value="提交" id="submit_<?php echo $val['id']; ?>"
                                   class="tijiao btn-info btn"/>
                            <?php
                        } else {
                            ?>
                            <!--
            <a target="_blank" href="<?php echo url::base(TRUE); ?>concession/index?id=<?php echo $val['id']; ?>" id="dayin_<?php echo $val['id']; ?>" class="dayin">打印报告单</a>
            <input type="button"   value="打印报告单" id="dayin_<?php echo $val['id']; ?>" class="dayin"/>
             -->
                            <input class="btn btn-success" type='button'
                                   onclick="return print(<?php echo $val['id']; ?>);"
                                   id="print<?php echo $val['id']; ?>" value='<?php if ($val['print_status'] == 1) {
                                echo '已打印';
                            } else {
                                echo '打印';
                            } ?>'/>

                            <?php
                        }

                        ?>
                    </td>

                </tr>

            </table>
        </form>
        <?php
    }
}
?>


<?php if (isset($page_links)) {
    echo $page_links;
} ?>

<script type="text/javascript">
    function chk_tr_display(tr, a) {
        if
        (document.getElementById(tr).style.display == 'none') {
            document.getElementById(tr).style.display = '';
            document.getElementById(a).innerHTML = '收起';
        }
        else {
            document.getElementById(tr).style.display = 'none';
            document.getElementById(a).innerHTML = '展开';
        }
    }

</script>
<script type="text/javascript">

    $(document).ready(function () {
        laydate.render({
            elem: '#date_from'
        });
        laydate.render({
            elem: '#date_to'
        });
        $("#status").val('10');
        //单击添加按钮后到不良品出库单
        $(".tijiao").click(function () {

            var ids = $(this).attr("id");//确认按钮的ID
            var lengs = ids.length;
            var id = ids.substr(7, lengs - 7);//不良产品的ID
            var unqualified_id = $("#unqualified_id_" + id).val();//不合格数量
            var fail_deal_way = $("#fail_deal_way_" + id).val();
            var warehouse_remark = $("#warehouse_remark_" + id).val();//备注
            warehouse_remark = warehouse_remark.replace(/(^\s*)|(\s*$)/g, "");
            if (warehouse_remark == '') {
                alert('请留下你的备注，以便以后检查！！！');
                return;
            }


            $.ajax({
                type: 'post',
                url: '<?php echo url::base(TRUE);?>handlequality/handlequality_check',
                dataType: 'html',
                data: 'warehouse_remark=' + warehouse_remark + '&id=' + id + '&unqualified_id=' + unqualified_id + '&fail_deal_way=' + fail_deal_way,
                async: false,
                success: function (data) {
                    alert(data);
                    //alert(data);
                    if (data == '操作成功') {

                        window.location.href = window.location.href;
                        window.location.reload;
                    }
                    else {
                        alert('操作有误');
                    }
                },
                error: function () {
                    alert("error");
                }
            });
        });

        $(".dayin").click(function () {
            var ids = $(this).attr("id");//确认按钮的ID
            var lengs = ids.length;
            var id = ids.substr(6, lengs - 6);//产品的ID
            //alert(id);return;
            //var fail_deal_way=$("#way_"+id).val();


            $.ajax({
                type: 'get',
                url: '<?php echo url::base(TRUE);?>concession/index',
                dataType: 'json',
                data: {'id': id},
                async: false,
                success: function (data) {
                    //alert(data);
                    if (data == true) {
                        window.location.href = window.location.href;
                        window.location.reload;
                    }
                },
                error: function () {
                    alert("error");
                }
            });
            //alert(price);
        });

        $("#supplier_id").keyup(function (e) {
            var $val = $(this).val();
            showHint($val);


        });

        $("#down").click(function () {
            var no_purchaseorder_id = $("select[name='no_purchaseorder_id']").val();
            var purchase_man_name = $("input[name='purchase_man_name']").val();
            var sku = $("input[name='sku']").val();
            var supplier = $("input[name='supplier']").val();
            var purchaseorder_id = $("input[name='purchaseorder_id']").val();
            var date_from_c = $("input[name='date_from_c']").val();
            var date_to_c = $("input[name='date_to_c']").val();
            var fail_deal_way = $("#fail_deal_way").find("option:selected").val();
            var status = $("#status_choose").val();

            var uri = 'purchase_man_name=' + purchase_man_name + '&sku=' + sku +
                '&supplier=' + supplier + '&purchaseorder_id=' + purchaseorder_id + '&date_from_c=' + date_from_c + '&date_to_c=' + date_to_c +
                '&status=' + status + '&fail_deal_way=' + fail_deal_way + '&no_purchaseorder_id=' + no_purchaseorder_id;

            window.location.href = "<?php echo URL::base()?>handlequality/download?" + uri + '&tableName=bad_product_delivery';
        });


    });


    function print(id) {

        // document.getElementById('tabll'+id).style.display = 'none';//
        // document.getElementById('print'+id).style.display = 'none';//
        var url = "<?php echo url::base(TRUE)?>concession/index?id=" + id;
        window.location.href = window.location.href;
        window.location.reload;
        //window.location.href=url;//
        window.open(url);
        return false

    }

    //根据供应商名字的一部分文字进行查询
    function showHint(str) {
        if (str.length == 0) {
            $("#supplier_id").val('');
            return false;
        }
        var url = "<?php echo URL::base() ?>receipt/select_supplier";
        url += "?name=" + str;
        url += "&sid=" + Math.random();
        $.getJSON(url, function (data) {
            $("#txtHint").html("");
            var $array = data.split(',');
            $.each($array, function (index, value) {
                $('<li>' + value + '</li>').appendTo($("#txtHint"));
                $("#txtHint").show();
                $('#txtHint li').click(function () {
                    $("#supplier_id").val($(this).text());
                    $(this).parent().hide();
                });
                $(document).click(function () {
                    $("#txtHint").hide();
                });
            });
        });
    }
    //按enter键提交
    /*$("input[name='warehouse_remark']").keydown(function (e) {
        return false;
    });*/
    //	    //onsubmit="return checkForm(this);"
    //	    function checkForm(this){
    //	    	var ids=$(this).attr("id");//确认按钮的ID
    //			var lengs=ids.length;
    //			var id=ids.substr(7,lengs-7);//不良产品的ID
    //			var warehouse_remark=$("#warehouse_remark_"+id).val();//备注
    //			warehouse_remark=warehouse_remark.replace(/(^\s*)|(\s*$)/g,"");
    //			if(warehouse_remark=='')
    //			{
    //				alert('请留下你的备注，以便以后检查！！！');return false;
    //			}else{
    //				return true;
    //			}
    //		}
</script>